import * as Router from 'koa-router';
const router = new Router();
router.prefix('/api')

import Baidu from '../controller/baidu/Baidu';

router.get('/baidu', function (ctx, next) {
    ctx.body = '百度'
})

router.get('/baidu/text2audio', async function (ctx, next) {

    try {
        const text = ctx.request.query.text;
        ctx.type = 'mp3';
        ctx.attachment(text + '.mp3')
        ctx.body = await Baidu.text2audio(text);
    } catch (e) {
        ctx.body = e;
    }

    next();
})

export default router
